package com.meilai.project.job;

import com.meilai.project.controller.web.report.helper.DateRangeHelper;
import com.meilai.project.mapper.business.installOrder.WorkOrderMapper;
import com.meilai.project.util.DateRange;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author chenxing
 */
@Component
public class AutoCalcRangeWorkOrderIdJob {

    @Autowired
    private WorkOrderMapper workOrderMapper;

    //每5分钟执行一次
    @Scheduled(cron = "0 0/5 * * * ?")
    @Transactional(rollbackFor = Exception.class)
    public void scheduleRemoveSnapShot() {
        workOrderMapper.clearWorkOrderIdRange();
        DateRange currentWeek = DateRangeHelper.calc(1);
        DateRange currentMonth = DateRangeHelper.calc(2);
        //新安装、巡检、维修、监播：创建时间-截止时间
        workOrderMapper.generateWorkOrderTypeOf1458(currentWeek.getBeginDate(),currentWeek.getEndDate(), 1);
        workOrderMapper.generateWorkOrderTypeOf1458(currentMonth.getBeginDate(),currentMonth.getEndDate(), 2);

        //上刊：（执行开始-7天）-截止时间
        workOrderMapper.generateWorkOrderTypeOf2(currentWeek.getBeginDate(),currentWeek.getEndDate(), 1);
        workOrderMapper.generateWorkOrderTypeOf2(currentMonth.getBeginDate(),currentMonth.getEndDate(), 2);

        //下刊：执行结束-截止时间
        workOrderMapper.generateWorkOrderTypeOf3(currentWeek.getBeginDate(),currentWeek.getEndDate(), 1);
        workOrderMapper.generateWorkOrderTypeOf3(currentMonth.getBeginDate(),currentMonth.getEndDate(), 2);

        //换画：执行开始-截止时间
        workOrderMapper.generateWorkOrderTypeOf7(currentWeek.getBeginDate(),currentWeek.getEndDate(), 1);
        workOrderMapper.generateWorkOrderTypeOf7(currentMonth.getBeginDate(),currentMonth.getEndDate(), 2);
    }
}
